package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.service.redpacket.RedPacketService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ywxie
 * @date 2019/12/4 17:01
 * @description
 */
@RestController
@RequestMapping("/api/redpacket")
public class RedPacketController {

    @Autowired
    private RedPacketService redPacketService;

    @RequiresPermissions("redpackageList:view")
    @GetMapping("")
    public BaseRsp getRedPacketRecord(@RequestParam(value = "limit", required = false, defaultValue = "20") String limit,
                                      @RequestParam(value = "offset", required = false, defaultValue = "0") String offset,
                                      @RequestParam(value = "from_uid", required = false) String fromUid,
                                      @RequestParam(value = "to_id", required = false) String toId,
                                      @RequestParam(value = "state", required = false) String state,
                                      @RequestParam(value = "startTime", required = false) String startTime,
                                      @RequestParam(value = "endTime", required = false) String endTime){
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("limit", limit);
        paramMap.put("offset", offset);
        if(fromUid != null){
            paramMap.put("from_uid", fromUid);
        }
        if(toId != null){
            paramMap.put("to_id", toId);
        }
        if(state != null){
            paramMap.put("state", state);
        }
        if(startTime != null){
            paramMap.put("start_time", startTime);
        }
        if(endTime != null){
            paramMap.put("end_time", endTime);
        }
        return new BaseRsp(ResultEnum.SUCCESS, redPacketService.listRedPacketAdminByConditions(paramMap));
    }

}
